package com.open.capacity.firebird.util;

import com.alibaba.druid.pool.DruidDataSource;
import com.open.capacity.common.model.DB;
import com.open.capacity.common.web.Result;
import com.open.capacity.firebird.config.DynamicDataSource;

public class DataSourceUtil {


    public static Result setFireBirdDataSource(DB db) {
        try {
            DruidDataSource druidDataSource = new DruidDataSource();
            druidDataSource.setUrl("jdbc:firebirdsql://localhost:3050/" + db.getDbUrl() + "?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&useAffectedRows=true");
            druidDataSource.setUsername(db.getDbUsername());
            druidDataSource.setPassword(db.getDbPassword());
//                }
            DynamicDataSource.dataSourcesMap.put("dbkey", druidDataSource);
            DynamicDataSource.setDataSource("dbkey");
            return Result.succeed("连接成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed("连接出错");
        }
    }

    public static void clear() {
        DynamicDataSource.clear();
    }
}
